﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Entity;
using MasoQna.Models;
using MasoQna.Infrastructure;

namespace MasoQna.Controllers
{
    public class HomeController : Controller
    {
        private MqDbContext context = new MqDbContext();

        public ActionResult Index()
        {
            List<Question> questions =
                (from q in context.Writings.OfType<Question>()
                     .Include(m => m.Writer)
                 orderby q.Time descending
                 select q).ToList();

            foreach (Question q in questions)
            {
                context.Entry(q).Collection(m => m.Answers).Load();
            }

            return View(questions);
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
